package com.demo.server;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;

import com.demo.thrift.ThriftMysqlService;

/**
 * 阻塞式多线程服务
 *
 * @author HuangKe
 * @date 2017年3月7日
 * @company Copyright © 2007-2016 www.zgxcw.com All Rights Reserved
 */
public class BlockMultiThreadServer {
	private static final int port = 8899;
	public static void main(String[] m) {
		//创建processor
		TProcessor tprocessor = new ThriftMysqlService.Processor<ThriftMysqlService.Iface>(new ThriftMyqlServiceImpl());
		try{
		//创建transport 阻塞通信
		TServerSocket serverTransport = new TServerSocket(port);
		//创建protocol  数据传输协议
		TBinaryProtocol.Factory protocol = new TBinaryProtocol.Factory();
		TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
		args.processor(tprocessor);
		args.protocolFactory(protocol);
		//创建服务器类型  多线程
		TServer server = new TThreadPoolServer(args);
		//开启服务
		System.out.println("---------开启阻塞式多线程服务---------");
		server.serve();
		System.out.println("---------开启阻塞式多线程服务---------");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
